package com.besall.allbase.view.activity.chipstoollevel4.protocol.fragments;

import android.content.Context;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import  bb.lanxing.R;
import com.besall.allbase.common.utils.ActivityUtils;

import java.util.List;


/**
 * A simple {@link Fragment} subclass.
 */
public class information extends Fragment implements View.OnClickListener {

    public String TAG = "information";
    private LinearLayout infoView1;
    private LinearLayout infoView2;
    public String[] cmds_1 = {"Get personal \ninformation", "Get Device Time", "Get Battery level", "Get device worn status","Get device charge status","Get lift wrist to view setting（old）",
            "Get lift wrist to view setting（new）","Get serial number","Get temp params","Get distance unit","Get mac address",
            "Get firmware version","Get automatic heart rate interval","Get sound volume","Get Phone book","Get watch size","get Amazon mic test volume","config weather control info",
            "switch and get broadcast name and mac address of BT","Unbind BT"};
    public String[] cmds_2 = {"Set personal \ninformation", "Set Time  Format\n", "Set Device mode\n", "Set Pairing phone type\n","Set Device Time\n","Set Time Zone time\n",
            "Set band show/hide screens","Set Hand preference","Set lift wrist to view setting（old）","Set lift wrist to view setting（new）","Set serial number","Set connection key",
            "Set time interval \nof the probe function","Set connection flow(Not Used)","Set temperature display tpye","Set Device auto monitor Temp","Set distance display unit",
            "set sound volume","set Phone book","set Amazon Alexa state","set Amazon Alexa Status","Set screen brightness","set Amazon mic test"};
    private Context mContext;

    InfoCallback mInfoCallBack;
    public information() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        mContext = inflater.getContext();
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_infomation, container, false);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        infoView1 = getActivity().findViewById(R.id.info_view1);
        infoView2 = getActivity().findViewById(R.id.info_view2);
        DisplayMetrics screen = new DisplayMetrics();
        getActivity().getWindowManager().getDefaultDisplay().getMetrics(screen);
        int width = screen.widthPixels;

        for (int i = 0; i < cmds_1.length; i++) {
            View view = new View(mContext);
            view.setId(i);
            view.setLayoutParams(new ViewGroup.LayoutParams((int) (width * 0.45), 20));

            Button button = new Button(mContext);
            button.setText("    " + cmds_1[i]);
            button.setId(i);
            button.setOnClickListener(this);
            button.setTextSize(10);
            button.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
            button.setGravity(Gravity.CENTER_VERTICAL);
            button.setBackgroundResource(R.drawable.rectangle_cardbtn);

            infoView1.addView(button);
            infoView1.addView(view);
        }

        for (int i = 0; i < cmds_2.length; i++) {
            View view = new View(mContext);
            view.setId(i);
            view.setLayoutParams(new ViewGroup.LayoutParams((int) (width * 0.45), 20));

            Button button = new Button(mContext);
            button.setText("    " + cmds_2[i]);
            button.setId(i + 100);
            button.setOnClickListener(this);
            button.setTextSize(10);
            button.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
            button.setGravity(Gravity.CENTER_VERTICAL);
            button.setBackgroundResource(R.drawable.rectangle_cardbtn);

            infoView2.addView(button);
            infoView2.addView(view);
        }
    }
    Toast toast;
    @Override
    public void onClick(View v) {
        if (mInfoCallBack != null){
            mInfoCallBack.onInfoProtocolClick(v.getId());
            Log.i(TAG, "onClick: " + v.getId());
            int id = v.getId();
            if (toast != null)
                toast.cancel();
            if (id < 100){
                toast = Toast.makeText(mContext, cmds_1[id],Toast.LENGTH_SHORT);
                toast.show();
            } else if (id > 100) {
                toast = Toast.makeText(mContext, cmds_2[id - 100],Toast.LENGTH_SHORT);
                toast.show();
            }
        }
    }

    public void setInfoCallback(InfoCallback infoCallback){
        mInfoCallBack = infoCallback;
    }

    public interface InfoCallback{

        void onInfoProtocolClick(int id);
    }
}

